﻿myApp.controller("OrderCtrl", ['$scope', '$http', '$routeParams', '$restUrls', '$post', '$rootScope', function ($scope, $http, $routeParams, $restUrls, $post, $rootScope) {
    var order_id = $routeParams.id;
    $scope.OrderInfo = {};
    $scope.freight = 0;
    $scope.GetOrderInfo = function (order_id) {
        $http({ method: "GET", url: $restUrls["getOrderInfo"], params: { order_id: order_id } }).success(function (result) {
            if (result.success == 1) {
                $scope.OrderInfo = result.data.order;
            }
        }).error(function (data, status, headers, config) {
            $.scojs_message('服务器忙,请稍候重试', $.scojs_message.TYPE_ERROR);
        });
    }
    $scope.GetOrderInfo(order_id);
    //获取订单邮费
    $scope.GetOrderfreight = function () {
        $http({ method: "GET", url: $restUrls["getOrderfreight"], params: { order_id: order_id,type:6 } }).success(function (result) {
            if (result.success == 1) {
                $scope.freight = result.data.order_total_info.value;
            }
        }).error(function (data, status, headers, config) {
            $.scojs_message('服务器忙,请稍候重试', $.scojs_message.TYPE_ERROR);
        });
    };
    //查看物流
    $scope.GoLoistics = function (Order, $event) {
        $event.stopPropagation();
        window.location.href = "/logistics.html/" + Order.order_id + "";
    };
}]);

myApp.controller("OrderListCtrl", ['$scope', '$http', '$routeParams', '$restUrls', '$post', '$rootScope', function ($scope, $http, $routeParams, $restUrls, $post, $rootScope) {
    var page = 1;
    $scope.OrderList = [];
    $http({ method: "GET", url: $restUrls["getOrderList"], params: { page: 1, limit: 10 } }).success(function (result) {
        if (result.success == 1) {
            $scope.OrderList = result.data.orders;
        }
    }).error(function (data, status, headers, config) {
        $.scojs_message('服务器忙,请稍候重试', $.scojs_message.TYPE_ERROR);
    });

    $('#orderlist').dropload({
        scrollArea: window,
        loadUpFn: function (me) {
            page = 1;
            $http({ method: "GET", url: $restUrls["getOrderList"], params: { page: page, limit: 10 } }).success(function (result) {
                if (result.success == 1) {
                    $scope.OrderList = result.data.orders;
                    me.resetload();
                } else {
                    me.resetload();
                };
            });
        },
        loadDownFn: function (me) {
            page = page + 1;
            $http({ method: "GET", url: $restUrls["getOrderList"], params: { page: page, limit: 10 } }).success(function (result) {
                if (result.success == 1) {
                    for (var i = 0; i < result.data.orders.length; i++) {
                        $scope.OrderList.push(result.data.orders[i]);
                    }
                    me.resetload();
                } else {
                    page = page - 1;
                    me.resetload();
                };
            }).error(function (data, status, headers, config) {
                page = page - 1;
                me.resetload();
            });
        }
    });
    //查看订单详情
    $scope.GoOrderInfo = function (Order) {
        window.location.href = "#/orderdetail/" + Order.order_id + "";
    }

    //查看物流
    $scope.GoLoistics = function (Order, $event) {
        $event.stopPropagation();
        window.location.href = "#/logistics/" + Order.order_id + "";
    };
    //评价
    $scope.GoReview = function (Order, $event) {
        $event.stopPropagation();
        var product_id = Order.products[0].product_id;
        window.location.href = "#/addreview/" + product_id + "";
    }
}]);